﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AddFood.aspx.cs" Inherits="WebApplication1.AddFood" MasterPageFile="~/masterpage/User.Master" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="aspx" %>
<asp:Content ID="Content1" runat="server" ContentPlaceHolderID="ContentPlaceHolder1">
    <script src="js/prettify.js"></script>
    <script src="js/bootstrap-datepicker.js"></script>


    <%--Begin Loading ajax section--%>
    <aspx:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></aspx:ToolkitScriptManager>
    <asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1">
        <ProgressTemplate>
            <div style="position: fixed; text-align: center; height: 100%; width: 100%; top: 0; right: 0; left: 0; z-index: 9999999; background-color: #000000; opacity: 0.7;">
                <div class="center">

                    <img alt="" src="images/loading.gif" />

                </div>
            </div>
        </ProgressTemplate>
    </asp:UpdateProgress>
    <%--End Loading ajax section--%>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <Triggers>

             <asp:PostBackTrigger ControlID="btnAddFood" />
        </Triggers>
        <ContentTemplate>
            <div class="container-fluid">

                <fieldset>
                    <legend>Add Food</legend>
                </fieldset>
                <!-- Grid 12  -->
                <div class="control-group col-md-12 well">
                    <!-- Alert Message -->
                    <asp:Panel ID="divMessage" runat="server" class="alert alert-danger  alert-dismissible" Visible="False" role="alert">
                        <button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                        <asp:Label ID="lblMessage" runat="server" Text="">
                         
                        </asp:Label>
                    </asp:Panel>
                    <label class="control-label">Food Name:</label>
                    <div class="controls">
                        <asp:TextBox runat="server" ID="txtName" class="form-control" ToolTip="Food name" MaxLength="199"></asp:TextBox>
                    </div>

                    <label class="control-label">Food Description:</label>
                    <div class="controls">
                        <textarea id="description" runat="server" name="description" class="form-control" rows="4"></textarea>
                    </div>

                    <label class="control-label">Price :</label>
                    <div class="controls">
                        <asp:TextBox runat="server" ID="txtPrice" class="form-control" ToolTip="Food price" MaxLength="10" onkeypress="return validatenumerics(event)"></asp:TextBox>
                    </div>

                    <label class="control-lable">Promotion</label>
                    <div class="control-label checkbox">

                        <label>
                            <asp:CheckBox ID="chkPromotion" runat="server" Text="Promotion?" AutoPostBack="true" OnCheckedChanged="chkPromotion_CheckedChanged"></asp:CheckBox>
                            <%-- <input type="checkbox">
                        Promotion ?--%>
                        </label>
                        <div class="control-label">
                            Promotion Price:
                       
                        <asp:TextBox runat="server" ID="txtPromotionPrice" class="form-control" Enabled="false" onkeypress="return validatenumerics(event)" MaxLength="30" ToolTip="Promotional food price"></asp:TextBox>
                        </div>
                    </div>




                    <label class="control-label">Date available</label>
                    <div class="control-label">

                        <table class="table">
                            <thead>
                                <tr>

                                    <th>Start Date:
                                        <asp:TextBox runat="server" class="form-control" ID="dpdStart" ClientIDMode="Static" data-date-format="mm/dd/yyyy"></asp:TextBox></th>
                                    <th>End  Date:
                                        <asp:TextBox runat="server" class="form-control" ID="dpdEnd" ClientIDMode="Static" data-date-format="mm/dd/yyyy"></asp:TextBox></th>
                                </tr>
                            </thead>
                        </table>

                    </div>

                    <div class="control-label">
                        <label for="exampleInputFile">Photo Upload :</label>
                        <%--           <aspx:asyncfileupload onclientuploaderror="uploadError" onclientuploadcomplete="uploadComplete"
                            runat="server" id="AsyncFileUpload1" width="400px" uploaderstyle="Modern" completebackcolor="White"
                            uploadingbackcolor="#CCFFFF" throbberid="imgLoader" onuploadedcomplete="UploadComplete" />
                        --%>
                        <br />
                        <asp:Label ID="lblMesg" runat="server" Text=""></asp:Label>

                        <%--    <aspx:AjaxFileUpload ID="AjaxFileUpload1" runat="server" ThrobberID="myThrobber"
                            AllowedFileTypes="jpg,jpeg" MaximumNumberOfFiles="1" OnUploadComplete="FileUploadComplete" OnClientUploadComplete="showConfirmation"  />--%>
                        <asp:FileUpload ID="fileUpload" runat="server" />
                        <asp:Label ID="lblImage" runat="server" Text=""></asp:Label>
                    </div>





                    <script>
                        /* auto upload once is uploaded */
                        //if (Sys.Extended.UI.AjaxFileUpload.Control) {
                        //    var legacyaddFileToQueue = Sys.Extended.UI.AjaxFileUpload.Control.prototype.addFileToQueue;
                        //    Sys.Extended.UI.AjaxFileUpload.Control.prototype.addFileToQueue = function (fileItem) {
                        //        if (legacyaddFileToQueue.apply(this, [fileItem])) {
                        //            this._isUploading = true;
                        //            this.enableControls(this._isUploading);
                        //            this._processor.startUpload();
                        //        }
                        //    };
                        //}

                        //function uploadComplete() {
                        //    alert('upload complete.');
                        //}

                        //function uploadError()
                        //{
                        //    alert('Error!')
                        //}

                       
                        $(function () {
                            window.prettyPrint && prettyPrint();

                            // disabling dates
                            var nowTemp = new Date();
                            var now = new Date(nowTemp.getFullYear(), nowTemp.getMonth(), nowTemp.getDate(), 0, 0, 0, 0);

                            var checkin = $('#dpdStart').datepicker({
                                onRender: function (date) {
                                    return date.valueOf() < now.valueOf() ? 'disabled' : '';
                                }
                            }).on('changeDate', function (ev) {
                                if (ev.date.valueOf() > checkout.date.valueOf()) {
                                    var newDate = new Date(ev.date)
                                    newDate.setDate(newDate.getDate() + 1);
                                    checkout.setValue(newDate);
                                }
                                checkin.hide();
                                $('#dpdEnd')[0].focus();
                            }).data('datepicker');
                            var checkout = $('#dpdEnd').datepicker({
                                onRender: function (date) {
                                    return date.valueOf() < checkin.date.valueOf() ? 'disabled' : '';
                                }
                            }).on('changeDate', function (ev) {
                                checkout.hide();
                            }).data('datepicker');
                        });
                        $(document).ready()
                        {
                            var div = $("h2:contains('0')").parent();
                            div.removeClass("corner");
                            div.addClass("Nocorner")
                            div.find("h2").remove();


                        }

                    </script>

                    <div class="control-group">
                        <label class="control-label"></label>
                        <div class="controls">

                            <asp:Button ID="btnAddFood" runat="server" class="btn  btn-primary" Text="Add" OnClick="btnAddFood_Click" />
                            <asp:Button ID="btnClear" runat="server" class="btn  btn-primary" Text="Clear" OnClick="btnClear_Click" />
                        </div>
                    </div>



                    <br />
                    <fieldset>
                        <legend>Food List</legend>
                    </fieldset>
                    <div class="row">
                        <asp:Repeater ID="Repeater1" runat="server">
                            <ItemTemplate>
                                <div id='<%# "Panel"+ Eval("Id")%>' class="col-sm-4 col-lg-4 col-md-4 corner">
                                    <h2 id='<%# "H2"+ Eval("Id")%>'><%#Eval("isPromotion").ToString() =="1" ? "Promotion": "0" %></h2>
                                    <div class="thumbnail">
                                        <img alt="" src='<%#  "GetImage.aspx?id=" +  Eval("Id") %>' />
                                        <div class="caption">
                                            <h4 class="pull-right">RM<%# Eval("FoodPrice")%></h4>
                                            <h4><b><%# Eval("FoodName")%> </b>
                                            </h4>
                                            <p><%# Eval("FoodDescription")%></a>.</p>
                                            <asp:Button ID="btnEdit" runat="server" class="btn btn-primary" Text="Edit" CommandArgument='<%# Eval("Id")%> ' OnClick="btnEdit_Click"></asp:Button>
                                            <%--   <a href="#" class="btn btn-lg btn-primary" data-toggle="modal" data-target="#basicModal">Edit</a>--%>
                                            <a href="#" class="btn btn-primary" data-toggle="modal" data-target="<%# "#basicModal"+ Eval("Id")%>">Delete</a>
                                        </div>
                                        <div id="edit">
                                            <!-- Order modal -->
                                            <asp:HiddenField ID="hdFoodId" Value='<%# Eval("Id")%>' runat="server" />

                                            <div class="modal fade" id="<%# "basicModal"+ Eval("Id")%>" tabindex="-1" role="dialog" aria-labelledby="<%# "basicModal"+ Eval("Id")%>" aria-hidden="true">
                                                <div class="modal-dialog">
                                                    <div class="modal-content">
                                                        <div class="modal-header">
                                                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                                                            <h4 class="modal-title" id="myModalLabel">Delete</h4>
                                                        </div>
                                                        <div class="modal-body">
                                                            <label class="control-label">Delete?</label>
                                                            <div class="controls">
                                                                Confirm to delete ?
                                                            </div>
                                                        </div>
                                                        <div class="modal-footer">
                                                            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                                                            <asp:Button runat="server" class="btn btn-primary" Text="Delete" OnClick="btnDelete_Click" CommandArgument='<%# Eval("Id")%>' CommandName='<%# Eval("FoodName")%>' OnClientClick="$('.modal-backdrop').remove();"></asp:Button>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>

                                    </div>
                                </div>
                            </ItemTemplate>
                        </asp:Repeater>




                    </div>
                </div>

                <div class="control-group col-md-4"></div>

              

            </div>
        </ContentTemplate>
    </asp:UpdatePanel>

</asp:Content>


